package com.asset.service;

import com.asset.dao.ProductDao;
import com.asset.dao.PurchaseDao;
import com.asset.entity.Purchase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class PurchaseService {
    @Autowired
    private PurchaseDao purchaseDao;
    @Autowired
    private ProductDao productDao;


    //查询购置表业务
    public List<Purchase> purchaseList() {
        return purchaseDao.purchaseList();
    }

    //添加购置表
    @Transactional(rollbackFor = Exception.class) // 指定所有异常都回滚事务
    public void addPurchase(Purchase purchase) {
        //往购置表添加数据
        purchaseDao.addPurchase(purchase);

        //往商品表添加数据
        productDao.addProduct(purchase.getProductList());

    }


    //根据id查询购置表
    public Purchase getById(String id) {
        return purchaseDao.getById(id);

    }
}
